/**
 *Npc Advance
 */

/**
 * 标准抬头
 * @type {{}}
 */
var clientfileheader = {}

clientfileheader.INSTANCE_KEY = "Charactersbase"
clientfileheader.HanderCount = 0

var clientfileNode = {}

clientfileheader.g_CanvasDialoguePaneltext
clientfileheader.g_CanvasDialoguePanel

/**
 * 标准变量
 * @type {{}}
 */

var filevarcharacter = {}
filevarcharacter.DialoguePanelInitialPosition_X
filevarcharacter.DialoguePanelInitialPosition_y

globalThis.npc = window

npc.TriggerConversation = async function (str, dur, dur2) {
    await TriggerConversation(str, dur, dur2)
}

c3.c3_Initfram(clientfileheader.INSTANCE_KEY, () => {
    clientfileheader.g_CanvasDialoguePanel = INSTANCE_IS("talk_bar")
    clientfileheader.g_CanvasDialoguePaneltext = INSTANCE_IS("talk_text")

    if (clientfileheader.g_CanvasDialoguePaneltext == null || clientfileheader.g_CanvasDialoguePanel == null) return

    filevarcharacter.DialoguePanelInitialPosition_X = clientfileheader.g_CanvasDialoguePanel.x
    filevarcharacter.DialoguePanelInitialPosition_y = clientfileheader.g_CanvasDialoguePanel.y
})

c3.c3_Initfram(clientfileheader.INSTANCE_KEY, () => {
    HideDialoguePane()
})

c3.c3_Updatefram(clientfileheader.INSTANCE_KEY, () => {
    if (clientfileheader.g_CanvasDialoguePaneltext == null && clientfileheader.g_CanvasDialoguePanel == null) return
    clientfileheader.g_CanvasDialoguePaneltext.opacity = clientfileheader.g_CanvasDialoguePanel.opacity
    clientfileheader.g_CanvasDialoguePaneltext.x = clientfileheader.g_CanvasDialoguePanel.x
    clientfileheader.g_CanvasDialoguePaneltext.y = clientfileheader.g_CanvasDialoguePanel.y
})

c3.c3_Initfram(clientfileheader.INSTANCE_KEY, async () => {

})


/**
 * @param str // 对话的文字
 * @param dur // 显示打字机完整对话的时间 单位/s
 * @param dur2 // 对话框停留时间 单位/ms
 * @returns {Promise<void>}
 */

async function TriggerConversation(str, dur, dur2) {
    CallDialoguePanel()
    if (clientfileheader.g_CanvasDialoguePaneltext == null || clientfileheader.g_CanvasDialoguePanel == null) return
    var durtime = dur
    clientfileheader.g_CanvasDialoguePaneltext.typewriterText(str, durtime)
    await wt(dur2)
    EndConversation()
}

function EndConversation() {
    ReboundDialoguePanel()
    clientfileheader.g_CanvasDialoguePanel.x = filevarcharacter.DialoguePanelInitialPosition_X
    clientfileheader.g_CanvasDialoguePanel.y = filevarcharacter.DialoguePanelInitialPosition_y
}

function ReboundDialoguePanel() {
    e_Invoke("npc_talk_call_bar")
}

function CallDialoguePanel() {
    e_Invoke("npc_talk_back_bar")
}

function HideDialoguePane() {
    clientfileheader.g_CanvasDialoguePanel.opacity = 0
}


async function TestDialogue() {
    await TriggerConversation("hi fuck", 1.1, 1500)
    await TriggerConversation("林琴", 0.5, 1500)
    await TriggerConversation("this is test message u can speak in there", 1, 4300)
    await TriggerConversation("normal use in npc  talk grapha text", 1, 4300)
    await TriggerConversation("just testhi", 1, 4300)
}


